package edu.neusoft.springhtmldemo.controller;

import edu.neusoft.springhtmldemo.domain.InspectionManagement;
import edu.neusoft.springhtmldemo.service.InspectionManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class InspectionManagementController {
    @Autowired
    private InspectionManagementService service;

    @RequestMapping("inspectionManagementShow")
    public List<InspectionManagement> inspectionManagementShow(){
//        System.out.println("here");
        List<InspectionManagement> lists=service.showAll();
//        for (InspectionManagement list : lists) {
//            System.out.println(list);
//        }
        return lists;
    }

    @RequestMapping("updateInspectionManagement")
//    public void  updateInspectionManagement(String inspectionBeginTime){
    public void updateInspectionManagement(String inspectionNum,String inspectionName,Float inspectionSpd,String inspectionBeginTime,Float inspectionCycle,Integer isInspection){
//        System.out.println(inspectionNum+"-"+inspectionSpd+"-"+inspectionBeginTime+"-"+inspectionCycle+"-"+isInspection);
//        System.out.println(inspectionBeginTime);
        service.updateInspectionManagement(inspectionNum,inspectionName,inspectionSpd,inspectionBeginTime,inspectionCycle,isInspection);
    }

    @RequestMapping("selectInspectionManagement")
    public List<InspectionManagement> selectInspectionManagement(String inspectionNum,String inspectionName,String inspectionSpd,String inspectionBeginTime,String inspectionCycle,String isInspection){
                System.out.println(inspectionNum+"-"+inspectionSpd+"-"+inspectionBeginTime+"-"+inspectionCycle+"-"+isInspection);

        if(inspectionBeginTime.length()>0){
            inspectionBeginTime=inspectionBeginTime.substring(0,10);
        }

        return service.selectInspectionManagement(inspectionNum,inspectionName,inspectionSpd,inspectionBeginTime,inspectionCycle,isInspection);
    }

    @RequestMapping("addInspectionManagement")
    public void addInspectionManagement(@Validated InspectionManagement management){
//        System.out.println(management);
        service.addInspectionManagement(management);
    }

    @RequestMapping("delInspectionManagement")
    public void delInspectionManagement(Integer inspectionNum){
        service.delInspectionManagement(inspectionNum);
    }
}
